﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace FooFun.DataElements.Dtos
{
    public class XmlAttributeDataElement : DataElement
    {

        public override string ToString()
        {
            return this.Value.ToString();
        }

        XmlAttribute attr;

        XmlNode node;

        public XmlAttributeDataElement(XmlAttribute attr, XmlNode node)
        {
            this.attr = attr;
            this.node = node;
        }

        public XmlAttributeDataElement(XmlAttribute attr)
        {
            this.attr = attr;
            this.node = attr.OwnerElement;
        }

        #region IDataElement 成员

        public override object Value
        {
            get
            {
                return attr.Value;
            }
            set
            {
                if (this.attr.OwnerElement == null)
                {
                    this.node.Attributes.Append(attr);
                }
                this.attr.Value = value.ToString();
            }
        }

        public override bool IsEmpty
        {
            get { return String.IsNullOrEmpty(this.attr.Value); }
        }

        #endregion
    }
}
